package me.yokeyword.fragmentation.extensions;

import ohos.aafwk.ability.fraction.Fraction;
import ohos.aafwk.ability.fraction.FractionScheduler;

/*
 * Wrapper support setArguments and BackStack record
 * */

public class FractionSchedulerEx extends FractionScheduler {
    FractionScheduler fs;
    FractionBackStack fbs;

    FractionSchedulerEx(FractionScheduler fs, FractionBackStack fbs) {
        this.fs = fs;
        this.fbs = fbs;
    }

    public FractionScheduler add(int containerComponentId, Fraction fraction) {
        fbs.checkNewRecordOrAdd(fraction).setActive(true);
        return fs.add(containerComponentId, fraction);
    }

    public FractionScheduler add(int containerComponentId, Fraction fraction, String tag) {
        fbs.checkNewRecordOrAdd(fraction).setTag(tag).setActive(true);
        return fs.add(containerComponentId, fraction, tag);
    }

    public FractionSchedulerEx replace(int containerComponentId, Fraction fraction) {
        fbs.checkNewRecordOrAdd(fraction).setActive(true);
        fs.replace(containerComponentId, fraction);
        return this;
    }

    @Override
    public FractionScheduler remove(Fraction fraction) {
        fbs.remove(fbs.findActiveFractionEx(fraction));
        return fs.remove(fraction);
    }

    @Override
    public FractionScheduler hide(Fraction fraction) {
        return null;
    }

    public FractionSchedulerEx remove(FractionEx fraction) {
        remove(fraction.getFraction());
        return this;
    }

    public FractionScheduler hide(FractionEx fractionex) {
        fractionex.setHide();
        return fs.hide(fractionex.getFraction());
    }

    public FractionSchedulerEx show(Fraction fraction) {
        fs.show(fraction);
        return this;
    }

    public FractionSchedulerEx show(FractionEx fractionex) {
        fractionex.setUnHide();
        fs.show(fractionex.getFraction());
        return this;
    }

    public int submit() {
        return fs.submit();
    }

    public FractionScheduler pushIntoStack(String factionTag) {
        return fs.pushIntoStack(factionTag);
    }

    public void replace(int containerComponentId, FractionEx toF, String toFractionTag) {
        fs.replace(containerComponentId, toF.getFraction());
        fs.pushIntoStack(toFractionTag);
        toF.setActive(true);
    }
}
